﻿using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Drawing2D;

namespace BiliData
{
    class LabelExt : Label
    {
        /// <summary>
        /// 边宽
        /// </summary>
        public int BorderWidth { get; set; } = 1;
        /// <summary>
        /// 边颜色
        /// </summary>
        public Color BorderColor { get; set; } = Color.White;


        protected override void OnPaint(PaintEventArgs e)
        {
            DrawText(e.Graphics);
        }

        private void DrawText(Graphics g)
        {
            g.FillRectangle(new SolidBrush(BackColor), ClientRectangle);
            using (GraphicsPath gp = new GraphicsPath())
            using (Pen outline = new Pen(BorderColor, BorderWidth)
            { LineJoin = LineJoin.Round })
            using (StringFormat sf = new StringFormat())
            using (Brush foreBrush = new SolidBrush(ForeColor))
            {
                gp.AddString(Text, Font.FontFamily, (int)Font.Style,
                    Font.Size, ClientRectangle, sf);
                g.ScaleTransform(1.3f, 1.35f);
                g.SmoothingMode = SmoothingMode.HighQuality;
                g.DrawPath(outline, gp);
                g.FillPath(foreBrush, gp);
            }
        }
    }
}